#!/usr/bin/env python3
import os
import pickle
import datetime
import glob

def _Get_ID():
    today = datetime.date.today()
    name = today.strftime(".%Y-%m-%d")
    gid = 1
    if os.path.exists(name):
        gid = pickle.load(open(name, 'br'))
        gid += 1
    
    pickle.dump(gid, open(name, 'wb'))
    return ("GS{}{:03d}".format(today.strftime("%Y%m%d"), gid))

def Get_ID(sample_date):
    dirname = "out/"+sample_date
    if os.path.exists(dirname):
        pdf = glob.glob(dirname + "/*.pdf")
        tmp = sample_date.split('/')
        date = "".join(tmp)
        return "GS{}{:03d}".format(date, len(pdf)+1)
    else:
        os.makedirs("out/"+sample_date)
        tmp = sample_date.split('/')
        tmp.append("001")
        return 'GS' + "".join(tmp)

if __name__ == "__main__":
    idd = Get_ID("2020/11/05")
    print(idd)
